/* eslint-disable no-empty-pattern */
import { api_add } from '@/api/crud'
import { api_modifyRouteIdByIdPurview, api_getRouteIdByIdPurview } from '@/api/sys_purview_route'

const pathName = 'purview-route'

const state = {}

const mutations = {}

const actions = {
  // 添加一条权限和前端路由绑定的记录
  add({}, purviewRoute) {
    return new Promise((resolve, reject) => {
      api_add(pathName, purviewRoute)
        .then(() => {
          resolve()
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 修改某条权限绑定的路由
  modifyRouteIdByIdPurview({}, paramsJson) {
    return new Promise((resolve, reject) => {
      api_modifyRouteIdByIdPurview(paramsJson)
        .then(() => {
          resolve()
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
  // 根据权限id查到绑定的路由id
  getRouteIdByIdPurview({}, idPurview) {
    return new Promise((resolve, reject) => {
      api_getRouteIdByIdPurview(idPurview)
        .then((response) => {
          resolve(response.data.data)
        })
        .catch((error) => {
          reject(error)
        })
    })
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
}
